<template>
  <div class="app-container">
    <el-row :gutter="12">
      <el-col :span="4">
        <el-card shadow="always">
          全县预算: {{cgsum.mysum}}万元
        </el-card>
      </el-col>
      <el-col :span="3">
        <el-card shadow="always">
          全县总数:{{cgsum.total}}笔
        </el-card>
      </el-col>
    </el-row>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">


      <el-form-item label="项目名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:hgtcrawlers:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="hgtcrawlersList" @selection-change="handleSelectionChange"@row-click="openDetails">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="发布时间" align="center" prop="sendTime" />
      <el-table-column label="采购时间" align="center" prop="expectTime" />
      <el-table-column label="项目名称" align="center" prop="name" show-overflow-tooltip="true"/>
      <el-table-column label="网址" align="center" prop="url" show-overflow-tooltip="true" />
      <el-table-column label="预算" align="center" prop="budget" />
      <el-table-column label="公司名称" align="center" prop="sendCompany" show-overflow-tooltip="true"/>
      <el-table-column label="标题" align="center" prop="title" show-overflow-tooltip="true"/>
      <el-table-column label="是否信息化" align="center" prop="isKey" />
      <el-table-column label="信息类型" align="center" prop="type" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listHgtcrawlers, tjsum, getHgtcrawlers, delHgtcrawlers, addHgtcrawlers, updateHgtcrawlers } from "@/api/system/hgtcrawlers";

export default {
  name: "Hgtcrawlers",
  data() {
    return {
      cgsum:{total:"",mysum:""},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招标信息表格数据
      hgtcrawlersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        sendTime: null,
        title: null,
        url: null,
        sendCompany: null,
        name: null,
        items: null,
        state: null,
        budget: null,
        expectTime: null,
        isKey: null,
        type: "中标公示",
        xiaquname: null,
        city: null,
        xiaqucode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.gettjsum()
  },
  methods: {
    /** 查询招标信息列表 */
    getList() {
      this.loading = true;
      listHgtcrawlers(this.queryParams).then(response => {
        this.hgtcrawlersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    gettjsum() {

      tjsum({type:"中标公示"}).then(response => {
        this.cgsum.mysum = response.data.resultData.sum;
        this.cgsum.total = response.data.resultData.total;


      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sendTime: null,
        title: null,
        url: null,
        sendCompany: null,
        name: null,
        items: null,
        state: null,
        budget: null,
        expectTime: null,
        remark: null,
        isKey: null,
        type: "中标公示",
        xiaquname: null,
        city: null,
        xiaqucode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加招标信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHgtcrawlers(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改招标信息";
      });
    },
    openDetails(row) {
      window.open(row.url, "_blank");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHgtcrawlers(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHgtcrawlers(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除招标信息编号为"' + ids + '"的数据项？').then(function() {
        return delHgtcrawlers(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/hgtcrawlers/export', {
        ...this.queryParams
      }, `hgtcrawlers_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
